package cn.yeyiu.util;

import android.content.Context;

import java.io.File;
import java.nio.file.Files;

public class FileUtil {

    public static File getAndroidDataFile(Context context, String fileName){
        return new File(context.getExternalFilesDir("").getPath()+"/"+fileName);
    }

    public static void getAndroidDataCache(Context context, String type){

    }

    public static void getAndroidDataMedia(Context context, String type){

    }

    public static void getDataFile(Context context, String type){

    }

    public static void getDataCache(Context context, String type){

    }

    public static boolean removeAndroidDataFile(Context context, String fileName){
        File f = getAndroidDataFile(context, fileName);
        if(f.exists()&&f.isFile()){
            return f.delete();
        }
        return false;
    }

    public static boolean removeAndroidDataDownloadFile(Context context,String type, String fileName){
        File f = getAndroidDataFile(context, "download/"+type+"/"+fileName);
        if(f.exists()&&f.isFile()){
            return f.delete();
        }
        return false;
    }

    public static boolean removeAndroidDataDownloadFolder(Context context, String type){
        File folder = getAndroidDataFile(context, "download/"+type);
        for (File f: folder.listFiles()){
            f.delete();
        }
        return true;
    }

    public static boolean removeAndroidDataDownload(Context context){
        File folder = getAndroidDataFile(context, "download");
        for (String type: folder.list()){
            removeAndroidDataDownloadFolder(context, type);
            removeAndroidDataFile(context, "download_"+type+".json");
        }
        return true;
    }


}
